<?php
/**
 * @abstract All the resources have to be one word
 * 
 */
class Product_WidgetController extends Clu_Controller_Action_Widget
{
	public function init()
	{
		$this->m = new product_Model_Product();
		parent::init();
	}
	
	public function listProductAction()
	{
		$sess = new Zend_Session_Namespace(CLU_NS);
        $user_id = $this->getParam('id');
        $this->viewParams['id'] = $user_id;
        $this->viewParams['mode'] = "edit";
        $this->viewParams['form'] = new product_Form_Product();
        $actionUrl = $this->widgetService->getView()->hvnUrl(array('module' => 'product', 'action'=>'new'), 'nocontroller');
        $this->viewParams['form']->cluBuild(array('action' => 'new', 'action_url' => $actionUrl));
        if(isset($requestData))
        	$this->viewParams['form']->populateFormData($requestData);
        $data = array('status' => 'featured','item_per_page' => 5);
        if(isset($data['page']) == null)
			$data['page'] = 1 ;
			$data['user_id'] = $user_id ;
		$paginatorProduct = $this->getListProduct($data);
		
       	$this->viewParams['paginator'] = $paginatorProduct;
		$this->viewParams['productList'] =  $paginatorProduct->getCurrentItems();	
		$this->viewParams['user_id'] =  $user_id;
			
	}

    public function getListProduct($data)
	{
	   	$select = $this->m->search($data);
	   	$paginator = $this->generatePaginator($select, $data['page'], $data['item_per_page'], 7, 'Jumping');
	   	$sess = new Zend_Session_Namespace("paginatorProduct");
        return $paginator;
	}  

    public function viewAction() 
    {
    	// $this->viewParams['id'] = $_REQUEST['id'];
    	 //die($this->viewParams['id']);
    	if(isset($_REQUEST['product_id'])){
		$productId = $_REQUEST['product_id'];
		$this->viewParams['views'] = $this->m->findByPrimary($productId);
    	 }
    }
    
}    
